package state

import (
	"fmt"
	"utilx/logx"
)

type ItemRequestedState struct {
	vendingMachine *VendingMachine
}

func (i *ItemRequestedState) name() string {
	return "ItemRequestedState"
}
func (i *ItemRequestedState) requestItem() error {
	return fmt.Errorf("Item already requested")
}

func (i *ItemRequestedState) addItem(count int) error {
	return fmt.Errorf("Item Dispense in progress")
}

func (i *ItemRequestedState) insertMoney(money int) error {
	if money < i.vendingMachine.itemPrice {
		return fmt.Errorf("ItemRequestedState Inserted money is less. Please insert %d", i.vendingMachine.itemPrice)
	}
	logx.Debug("ItemRequestedState:Money entered is ok")
	i.vendingMachine.SetCurrentState(i.vendingMachine.hasMoney)
	return nil
}
func (i *ItemRequestedState) dispenseItem(count int) error {
	return fmt.Errorf("ItemRequestedState Please insert money first")
}
